package com.cafuc.base;

import org.apache.commons.lang3.StringUtils;
//import sun.nio.cs.ext.MacHebrew;

import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringOperation {
    public void stringTest(){
        String a = "Do things you fear and the death of fear is certain";
        System.out.println(a.length());
        System.out.println(a.indexOf(" "));
        System.out.println(a.replace("o","QQQ"));
        System.out.println(a.replaceAll("o", "QQQ"));
        System.out.println(Arrays.asList(a.split(" ")));
        System.out.println(a.substring(0, 10));

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("wfq").append("you").append(2);
        System.out.println(stringBuffer.toString());

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Sponge").append("baby").append(1);
        System.out.println(stringBuilder.toString());

        StringTokenizer stringTokenizer = new StringTokenizer(a, " ");
        while(stringTokenizer.hasMoreTokens()){
            System.out.println(stringTokenizer.nextToken());
        }
        //判断字符串非空
        if(StringUtils.isNotBlank(a)){
            System.out.println(a);
        }
        //"==" （对基本数据类型对值的判断，String类型数据判断的是地址）
        // "equals"（对基本数据是对地址的判断，String类型数据判断的是值）
        int i = 1;
        int j = 1;
        String aa = "daxunhua";
        String bb = "daxunhua";
        String cc = new String("daxunhua");
        String dd = new String("daxunhua");
        System.out.println(i == j);
        System.out.println(aa == bb);
        System.out.println(aa == cc);
        System.out.println(cc == dd);
        System.out.println(aa.equals(cc));

        //正则表达式
        String emailRegex = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w]" +
                "(?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
        String email = "2812343305@qq.com";
        System.out.println(email.matches(emailRegex));
        Matcher matcher =  Pattern.compile(emailRegex).matcher(email);
        System.out.println(matcher.matches());
        //
        Matcher matcher1 = Pattern.compile("(\\d+)-(\\d+)-(\\d+)").matcher("2021-12-31");
        if(matcher1.find()){
            System.out.println(matcher1.group(0));
            System.out.println(matcher1.group(1));
            System.out.println(matcher1.group(2));
            System.out.println(matcher1.group(3));
        }
        System.out.println(email.replaceAll("3.*?@", "3***@"));
    }

    public static void main(String[] args){
        StringOperation stringOperation = new StringOperation();
        stringOperation.stringTest();
    }
}
